<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | 王勇程 <laughskydragon@qq.com>                         |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\api\controller;

/**
 * 用户接口控制器
 */
class User extends ApiBase
{


    /**
     * 获取用户信息
     */
    public function getUserInfo()
    {
        $data = $this->filterApiParams(['user_token']);
        
        return $this->apiReturn($this->logicUser->getUserInfo($data));
    }

    /**
     * 更新用户信息
     */
    public function updateUserInfo()
    {
        $data = $this->filterApiParams(['user_token', 'nickname', 'avatar', 'avatar_id']);
        
        return $this->apiReturn($this->logicUser->updateUserInfo($data));
    }

    /**
     * 获取用户统计信息
     */
    public function getUserStats()
    {
        $data = $this->filterApiParams(['user_token']);
        
        return $this->apiReturn($this->logicUser->getUserStats($data));
    }

    /**
     * 获取用户VIP状态
     */
    public function getVipStatus()
    {
        $data = $this->filterApiParams(['user_token']);
        
        return $this->apiReturn($this->logicUser->getVipStatus($data));
    }

    /**
     * 检查并更新用户VIP状态
     */
    public function checkVipStatus()
    {
        $data = $this->filterApiParams(['user_token']);
        
        return $this->apiReturn($this->logicUser->checkAndUpdateVipStatus($data));
    }



    /**
     * 获取邀请统计
     */
    public function getInviteStats()
    {
        $data = $this->filterApiParams(['user_token']);
        
        return $this->apiReturn($this->logicUser->getInviteStats($data));
    }

    /**
     * 获取邀请记录
     */
    public function getInviteRecords()
    {
        $data = $this->filterApiParams(['user_token', 'page', 'limit']);
        
        return $this->apiReturn($this->logicUser->getInviteRecords($data));
    }



    /**
     * 检查用户状态
     */
    public function checkUserStatus()
    {
        $data = $this->filterApiParams(['user_token']);
        
        return $this->apiReturn($this->logicUser->checkUserStatus($data));
    }

    /**
     * 重置密码
     */
    public function resetPassword()
    {
        $data = $this->filterApiParams(['mobile', 'code', 'new_password']);
        
        return $this->apiReturn($this->logicUser->resetPassword($data));
    }



    /**
     * 绑定手机号
     */
    public function bindMobile()
    {
        $data = $this->filterApiParams(['user_token', 'mobile', 'code']);
        
        return $this->apiReturn($this->logicUser->bindMobile($data));
    }

    /**
     * 获取个人中心数据
     */
    public function getProfileData()
    {
        $data = $this->filterApiParams(['user_token']);
        
        return $this->apiReturn($this->logicUser->getProfileData($data));
    }
    
    /**
     * 获取微信群二维码
     */
    public function getWechatGroupQrcode()
    {
        $data = $this->filterApiParams(['user_token']);
        
        return $this->apiReturn($this->logicUser->getWechatGroupQrcode($data));
    }
    
    /**
     * 获取设置信息
     */
    public function getSettings()
    {
        $data = $this->filterApiParams(['user_token']);
        
        return $this->apiReturn($this->logicUser->getSettings($data));
    }
    
    /**
     * 更新设置信息
     */
    public function updateSettings()
    {
        $data = $this->filterApiParams(['user_token', 'notification_enabled', 'privacy_settings']);
        
        return $this->apiReturn($this->logicUser->updateSettings($data));
    }

    /**
     * 个人中心首页综合数据
     * 包含：用户信息、VIP状态、统计数据、快捷功能、最新消息
     */
    public function getDashboard()
    {
        $data = $this->filterApiParams(['user_token']);
        
        return $this->apiReturn($this->logicUser->getDashboard($data));
    }

    /**
     * 我的资产页面综合数据
     * 包含：余额信息、邀请收益、提现记录、收益统计
     */
    public function getMyAssets()
    {
        $data = $this->filterApiParams(['user_token']);
        
        return $this->apiReturn($this->logicUser->getMyAssets($data));
    }

    /**
     * 我的关注页面综合数据
     * 包含：关注列表、价格提醒、关注统计、推荐商品
     */
    public function getMyFollows()
    {
        $data = $this->filterApiParams(['user_token']);
        
        return $this->apiReturn($this->logicUser->getMyFollows($data));
    }

    /**
     * 个人设置页面综合数据
     * 包含：用户信息、系统设置、隐私设置、通知设置
     */
    public function getSettingsPage()
    {
        $data = $this->filterApiParams(['user_token']);
        
        return $this->apiReturn($this->logicUser->getSettingsPage($data));
    }

    /**
     * 过滤API参数
     */
    private function filterApiParams($fields = [])
    {
        $data = [];
        foreach ($fields as $field) {
            $value = $this->request->param($field);
            if ($value !== null) {
                $data[$field] = $value;
            }
        }
        return $data;
    }
}